home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / gcc / ixemlsrc.lha / ixemul / static / asctime.c next >
C/C++ Source or Header  |  1996-03-13  |  1KB  |  49 lines

  1. #include "private.h"
  2. #include "tzfile.h"
  3.  
  4. /*
  5. ** A la X3J11, with core dump avoidance.
  6. */
  7.  
  8. char *
  9. asctime(timeptr)
  10. register const struct tm *    timeptr;
  11. {
  12.     static const char    wday_name[][3] = {
  13.         "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
  14.     };
  15.     static const char    mon_name[][3] = {
  16.         "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  17.         "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
  18.     };
  19.     /*
  20.     ** Big enough for something such as
  21.     ** ??? ???-2147483648 -2147483648:-2147483648:-2147483648 -2147483648\n
  22.     ** (two three-character abbreviations, five strings denoting integers,
  23.     ** three explicit spaces, two explicit colons, a newline,
  24.     ** and a trailing ASCII nul).
  25.     */
  26.     static char        result[3 * 2 + 5 * INT_STRLEN_MAXIMUM(int) +
  27.                     3 + 2 + 1 + 1];
  28.     register const char *    wn;
  29.     register const char *    mn;
  30.  
  31.     if (timeptr->tm_wday < 0 || timeptr->tm_wday >= DAYSPERWEEK)
  32.         wn = "???";
  33.     else    wn = wday_name[timeptr->tm_wday];
  34.     if (timeptr->tm_mon < 0 || timeptr->tm_mon >= MONSPERYEAR)
  35.         mn = "???";
  36.     else    mn = mon_name[timeptr->tm_mon];
  37.     /*
  38.     ** The X3J11-suggested format is
  39.     **    "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %d\n"
  40.     ** Since the .2 in 02.2d is ignored, we drop it.
  41.     */
  42.     (void) sprintf(result, "%.3s %.3s%3d %02d:%02d:%02d %d\n",
  43.         wn, mn,
  44.         timeptr->tm_mday, timeptr->tm_hour,
  45.         timeptr->tm_min, timeptr->tm_sec,
  46.         TM_YEAR_BASE + timeptr->tm_year);
  47.     return result;
  48. }
  49.